package logic

import (
	"automated-modeling/automatedrpc/automatedrpc"
	"automated-modeling/automatedrpc/internal/svc"
	"automated-modeling/models/cache"
	"automated-modeling/models/mysql"
	"context"
	"fmt"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type CategoriesListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCategoriesListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CategoriesListLogic {
	return &CategoriesListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CategoriesListLogic) CategoriesList(in *automatedrpc.CategoriesListRequest) (*automatedrpc.CategoriesListResponse, error) {
	// todo: add your logic here and delete this line
	var categories []mysql.Categories

	var catego []*mysql.Categories
	for _, value := range categories {
		lisi := mysql.Categories{
			Name:    value.Name,
			Image:   value.Image,
			Profile: value.Profile,
			UserId:  value.UserId,
		}
		catego = append(catego, &lisi)
	}

	mysql.DB.Order("profile desc").Find(categories)

	fmt.Print(catego)
	cache.Rdb.Set(l.ctx, "categories", catego, time.Hour*24)
	return &automatedrpc.CategoriesListResponse{}, nil
}
